package cn.edu.xhu.library_management.area.mapper;

import cn.edu.xhu.library_management.area.entity.LmFloor;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Author: MMJ
 * @Date: 2022 - 08 - 29
 * @Description: 楼层信息mapper类
 */
public interface FloorMapper {

    /**
     * 通过图书馆id，查询对应的所有楼层信息
     * @param infoId 图书馆ID
     * @return 楼层信息集合
     */
    @Select("select *from lm_floor where info_id = #{infoId}")
    @Results(id = "baseFloorResult",value = {
            @Result(id = true,column = "fl_id",property = "id"),
            @Result(column = "fl_index",property = "index"),
            @Result(column = "fl_allocate_area",property = "allocateArea"),
            @Result(column = "info_id",property = "infoId")
    })
    public List<LmFloor> findFloorsByInfoId(Integer infoId);

    /**
     * 通过楼层ID，查询楼层信息
     * @param id 楼层ID
     * @return 楼层信息对象
     */
    @Select("select *from lm_floor where fl_id = #{id}")
    @ResultMap("baseFloorResult")
    public LmFloor findFloorById(Integer id);

    /**
     * 添加楼层信息
     * @param floor 楼层对象
     * @return 返回受影响的行数
     */
    @Insert("insert into lm_floor (fl_index,fl_allocate_area,info_id ) " +
            "values (#{floor.index},#{floor.allocateArea},#{floor.infoId});")
    public int addFloor(@Param("floor") LmFloor floor);

    public int updateFloor(LmFloor floor);

    /**
     * 通过楼层ID，删除楼层
     * @param id 楼层ID
     * @return 返回受影响的行数
     */
    @Delete("delete from lm_floor where fl_id = #{id}")
    public int deleteFloorById(Integer id);
}
